﻿using LitJson;
using System.IO;
using System.Net;

namespace HeerLauncherCoreLibrary.Passport
{
    public class nide8auth
    {
        public string ID { get; set; }
        private readonly string BaseUrl = "https://auth2.nide8.com:233/ID/";
        public ServerHelper.ServerInfo ServerInfo { get; }

        /// <summary>
        /// 利用ID实例化，并解析服务器信息。
        /// </summary>
        /// <param name="ID">官网获取</param>
        public nide8auth(string ID)
        {
            this.ID = ID;
            BaseUrl = BaseUrl.Replace("ID", this.ID);
            var a = HttpWebRequest.Create(BaseUrl);

            var b = a.GetResponse();
            string jsonnText = new StreamReader(b.GetResponseStream()).ReadToEnd();
            ServerHelper.ServerInfo j = JsonMapper.ToObject<ServerHelper.ServerInfo>(jsonnText);
            ServerInfo = j;
        }
    }
}